const trackdataModel = require('../models/trackdatas.js')

class TrackdatasCtrl {

    async list() {
        let lst = await trackdataModel.find();
        return lst.map(m=>m.toJSON());
    }

    async create(trackdataData) {
        let trackdata = new trackdataModel(trackdataData);
        const a = await trackdata.save();
        return a.toJSON();
    }

    async retrieve(id) {
        let trackdata = await trackdataModel.findById(id);
        return trackdata?trackdata.toJSON(): null;
    }

    async upsert(id, trackdataData) {
        trackdataData.id = id;
        let trackdata = await trackdataModel.upsert(id, trackdataData);
        return trackdata.toJSON();
    }
    async removeById(id) {
        await trackdataModel.removeById(id);
        return 1;
    }
    async find(filter)
    {
        let r = await trackdataModel.find(filter);
        return r.map(e=>e.toJSON());
    }
}

module.exports = new TrackdatasCtrl();